package com.youaishujuhui.devops.web.controller.game;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.youaishujuhui.devops.web.domain.game.*;
import com.youaishujuhui.devops.web.po.DepartmentPO;
import com.youaishujuhui.devops.web.service.game.DepartmentService;
import com.youaishujuhui.devops.web.vo.Result;

@Controller
@RequestMapping("/game/department")
public class DepartmentController {
	
	@Autowired
    private DepartmentService departmentService;

    @RequestMapping("/page")
    public ModelAndView page(){
        return new ModelAndView("game/department");
    }

    @RequestMapping("/query")
    @ResponseBody
    public Result<List<Department>> query(){
        Result<List<Department>> result = new Result<>();

        List<Department> list = departmentService.query();
        if (list != null) {
        	for (Department d : list) {
        		departmentService._fetchLinks(d, null);
        	}
        }
        result.setData(list);
        result.setCode(Result.SUCCESS);

        return result;
    }
    
    @RequestMapping("/queryAll")
    @ResponseBody
    public Result<List<DepartmentPO>> queryAll(){
        Result<List<DepartmentPO>> result = new Result<>();

        List<DepartmentPO> list = departmentService.queryAll();
        result.setData(list);
        result.setCode(Result.SUCCESS);

        return result;
    }
}
